<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>查询特定日期范围内指定周数的周几日期</h1>
    开始日期：
    <input type="number" id="startYear" placeholder="年">
    <input type="number" id="startMonth" placeholder="月">
    <input type="number" id="startDay" placeholder="日"><br>
    开始周数：<input type="number" id="startWeekNumber" placeholder="周数"><br>
    结束周数：<input type="number" id="endWeekNumber" placeholder="周数"><br>
    周几（1 表示周一，2 表示周二等）：<input type="number" id="dayOfWeek" placeholder="周几"><br>
    <button onclick="findDateInRange()">查询</button><br>
    <div id="result"></div>
</body>
<script>
    function findDateInRange() {
      // 获取输入的日期范围和周数、周几
      let startYear = parseInt(document.getElementById('startYear').value);
      let startMonth = parseInt(document.getElementById('startMonth').value);
      let startDay = parseInt(document.getElementById('startDay').value);
      let startWeekNumber = parseInt(document.getElementById('startWeekNumber').value);
      let endWeekNumber = parseInt(document.getElementById('endWeekNumber').value);
      let dayOfWeek = parseInt(document.getElementById('dayOfWeek').value);

      let dates = findDatesInRange(startYear, startMonth, startDay, startWeekNumber, endWeekNumber, dayOfWeek);
      let resultDiv = document.getElementById('result');
      resultDiv.innerHTML = "结果：<br>" + dates.join("<br>");
    }

    function findDatesInRange(startYear, startMonth, startDay,  startWeekNumber, endWeekNumber, dayOfWeek) {
      let dates = [];
      for (let week = startWeekNumber; week <= endWeekNumber; week++) {
        let date = findDateInRangeSingle(startYear, startMonth, startDay, week, dayOfWeek);
        dates.push(date);
      }
      return dates;
    }

    function findDateInRangeSingle(startYear, startMonth, startDay,  weekNumber, dayOfWeek) {
      let startDate = new Date(startYear, startMonth - 1, startDay);
      let firstDayOfWeek = startDate.getDay();
      let daysDiff = (weekNumber - 1) * 7 + (dayOfWeek - firstDayOfWeek);
      let targetDate = new Date(startDate.getTime() + daysDiff * 24 * 60 * 60 * 1000);
      if (targetDate >= startDate) {
        return `第${weekNumber}周(${targetDate.getMonth() + 1}.${targetDate.getDate()<10?'0'+targetDate.getDate():targetDate.getDate()})`;
      } else {
        return "输入日期已过本周周"+dayOfWeek;
      }
    }
  </script>
</script>
</html>